fix(flows): paper_flow draft-schema + code-assembled UUIDs#88
Open
bluezdot wants to merge 8 commits into
Open
Conversation
Root-cause and fix design for paper_flow being unable to produce a Paper end-to-end (strict-schema rejection + LLM UUID hallucination/reuse). Chosen approach: nested id-less draft schema; code assembles all UUIDs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Transitional: unblocks Runner.run past strict-JSON-schema rejection of Paper's dict[UUID, TreeNode]. Superseded by the draft-schema design. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fixes end-to-end extraction: the Agent no longer emits UUIDs (eliminating strict-schema rejection and UUID hallucination/reuse); provenance is now code-owned. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… validates Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ale doc Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
paper_flowcould not produce aPaperend-to-end against a live model — a defect the test suite never caught because it mocks the SDK (scripts/verify.shstayed green). Running it for real surfaced three failure modes:Paper.Agent(output_type=Paper)fails atRunner.runwithUserError: Strict JSON schema is enabled…— key-independent.Paper→TreeKnowledge.nodes: dict[UUID, TreeNode]maps to an open-endedadditionalPropertiesobject, which strict mode forbids."paper_001","introduction") for the manyUUID-typed fields (id,root_node_id,node_id, thenodeskeys,Citation.tree_id/node_id).…-bdle-…for…-bd1e-…) and reused one UUID for two nodes (a duplicate JSON key that silently drops a node).Asking an LLM to hand-generate dozens of unique, valid, cross-referenced UUIDs is structurally unreliable.
Fix
Stop the LLM from ever touching an identifier:
quantmind/flows/_paper_draft.pydefines an id-lessDraftPaper(it is the root node: carriestitle/summary/content/citations/childrendirectly) with nestedDraftNode/DraftCitation.assemble_paper(...)is a pure function that walks the draft, mints everyuuid4(), wiresparent_id/children_ids/root_node_idand eachCitation.node_id/tree_id, and builds the realPaper.paper_flowsets the Agent'soutput_typetoAgentOutputSchema(DraftPaper, strict_json_schema=False)and derives provenance (SourceRef/as_of/ExtractionRef(flow="paper_flow", model=cfg.model)) in code rather than trusting the LLM.Design rationale:
docs/design/en/2026-07-07-paper-flow-draft-assembly.md.Verification
scripts/verify.shgreen: ruff, basedpyright, import-linter (apex contract intact), pytest — 247 tests, 89.79% coverage (floor 75%).Paperwith noextra_instructions, code-owned provenance, and no schema/UUID errors.output_typeto the non-strictDraftPaperschema so this regression cannot silently reappear behind mocks.Notes
DoiIdentifierstill raisesNotImplementedError(OA-PDF resolver is a separate follow-up).SourceRef.fetched_at/content_hashintentionally leftNonein this MVP; documented as follow-ups.🤖 Generated with Claude Code